package tk.pak0.audiomidifier.model.persistence;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public abstract class A_DataHolder {
	// Principal
	public int bpm = 100;
	public boolean liveMode = false;
	
	public int midioutPort = 0;
	
	// Configuración
	public int soundCard = 0;
	public int audioInput = 0;
	public int audioOutput = 0;
	public int midiDevice = 0;
	public int cuantize = 0;
	public int highMeasureNibble = 4;
	public int lowMeasureNibble = 4;
	
	// Avanzado
	public int maxNote = 0;
	public int minNote = 119;
	
	public int pDMethod = 0;
	public int hptIt = 0;
	public int smooth = 50;
	public boolean checkResample = false;
	public int sampleRate = 0;
	public int downSampleRate = 0;
	public int bufferSize = 0;
	
	public abstract void makePersistent() throws IOException;
	public abstract void getPersistence() throws IOException;
	public abstract void loadDefaults() throws IOException;
	
	public Map<String, Object> getDefaultsTessitura(){
		Map<String, Object> defaults = new HashMap<String, Object>();
		defaults.put("maxNote", this.maxNote);
		defaults.put("minNote", this.minNote);
		return defaults;
	}
	
	public Map<String, String> getValues(){
		Map<String,String> ret = new HashMap<String, String>();
		
		// Principal
		ret.put("bpm", String.valueOf(this.bpm));
		ret.put("liveMode", String.valueOf(this.liveMode));
		ret.put("midioutPort", String.valueOf(this.midioutPort));
		
		// Configuración
		ret.put("soundCard", String.valueOf(this.soundCard));
		ret.put("audioInput", String.valueOf(this.audioInput));
		ret.put("audioOutput", String.valueOf(this.audioOutput));
		ret.put("midiDevice", String.valueOf(this.midiDevice));
		ret.put("cuantize", String.valueOf(this.cuantize));
		ret.put("highMeasureNibble", String.valueOf(this.highMeasureNibble));
		ret.put("lowMeasureNibble", String.valueOf(this.lowMeasureNibble));
		
		// Avanzado
		ret.put("maxNote", String.valueOf(this.maxNote));
		ret.put("minNote", String.valueOf(this.minNote));
		
		ret.put("pDMethod", String.valueOf(this.pDMethod));
		ret.put("hptIt", String.valueOf(this.hptIt));
		ret.put("smooth", String.valueOf(this.smooth));
		ret.put("checkResample", String.valueOf(this.checkResample));
		ret.put("sampleRate", String.valueOf(this.sampleRate));
		ret.put("downSampleRate", String.valueOf(this.downSampleRate));
		ret.put("bufferSize", String.valueOf(this.bufferSize));
		
		return ret;
	}
	
	public void setValues(Map<String,String> values){
		// Principal
		this.bpm = Integer.parseInt(values.get("bpm"));
		this.liveMode = Boolean.parseBoolean(values.get("liveMode"));
		this.midioutPort = Integer.parseInt(values.get("midioutPort"));
		
		// Configuración
		this.soundCard = Integer.parseInt(values.get("soundCard"));
		this.audioInput = Integer.parseInt(values.get("audioInput"));
		this.audioOutput = Integer.parseInt(values.get("audioOutput"));
		this.midiDevice = Integer.parseInt(values.get("midiDevice"));
		this.cuantize = Integer.parseInt(values.get("cuantize"));
		this.highMeasureNibble = Integer.parseInt(values.get("highMeasureNibble"));
		this.lowMeasureNibble = Integer.parseInt(values.get("lowMeasureNibble"));
		
		// Avanzado
		this.maxNote = Integer.parseInt(values.get("maxNote"));
		this.minNote = Integer.parseInt(values.get("minNote"));
		
		this.pDMethod = Integer.parseInt(values.get("pDMethod"));
		this.hptIt = Integer.parseInt(values.get("hptIt"));
		this.smooth = Integer.parseInt(values.get("smooth"));
		this.checkResample = Boolean.parseBoolean(values.get("checkResample"));
		this.sampleRate = Integer.parseInt(values.get("sampleRate"));
		this.downSampleRate = Integer.parseInt(values.get("downSampleRate"));
		this.bufferSize = Integer.parseInt(values.get("bufferSize"));		
	}
}
